class Note {
  String? id;
  String title;
  String content;
  DateTime dateCreated;
  DateTime? dateModified;
  String foldId;  // 新增标签字段

  Note({
    this.id,
    required this.title,
    required this.content,
    required this.dateCreated,
    this.dateModified,
    this.foldId = '',  // 默认空列表
  });

  // 复制方法，方便更新
  Note copy({
    String? id,
    String? title,
    String? content,
    DateTime? dateCreated,
    DateTime? dateModified,
    String? foldId,
  }) {
    return Note(
      id: id ?? this.id,
      title: title ?? this.title,
      content: content ?? this.content,
      dateCreated: dateCreated ?? this.dateCreated,
      dateModified: dateModified ?? this.dateModified,
      foldId: foldId??this.foldId,
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'title': title,
      'content': content,
      'dateCreated': dateCreated.toIso8601String(),
      'dateModified': dateModified?.toIso8601String(),
      'foldId': foldId,  // 将标签列表转为逗号分隔字符串
    };
  }

  factory Note.fromMap(Map<String, dynamic> map) {
    return Note(
      id: map['id'],
      title: map['title'],
      content: map['content'],
      dateCreated: DateTime.parse(map['dateCreated']),
      dateModified: map['dateModified'] != null
          ? DateTime.parse(map['dateModified'])
          : null,
      foldId: map['foldId'] ?? '',  // 将字符串转回列表
    );
  }
}